home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / program / palis.lha / Palis / src / vpl / PalisViewGUI.c < prev    next >
C/C++ Source or Header  |  1992-09-02  |  6KB  |  257 lines

  1. /*
  2.  *  Source machine generated by GadToolsBox V2.0b
  3.  *  which is (c) Copyright 1991-1993 Jaba Development
  4.  *
  5.  *  GUI Designed by : Hans "Tim Cane" Buehler, Codex Design
  6.  */
  7.  
  8. #include <exec/types.h>
  9. #include <intuition/intuition.h>
  10. #include <intuition/classes.h>
  11. #include <intuition/classusr.h>
  12. #include <intuition/imageclass.h>
  13. #include <intuition/gadgetclass.h>
  14. #include <libraries/gadtools.h>
  15. #include <graphics/displayinfo.h>
  16. #include <graphics/gfxbase.h>
  17. #include <clib/exec_protos.h>
  18. #include <clib/intuition_protos.h>
  19. #include <clib/gadtools_protos.h>
  20. #include <clib/graphics_protos.h>
  21. #include <clib/utility_protos.h>
  22. #include <string.h>
  23. #include <clib/diskfont_protos.h>
  24.  
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/intuition_pragmas.h>
  27. #include <pragmas/gadtools_pragmas.h>
  28. #include <pragmas/graphics_pragmas.h>
  29. #include <pragmas/utility_pragmas.h>
  30.  
  31. #include "PalisViewGUI.h"
  32.  
  33. struct Screen         *Scr = NULL;
  34. UBYTE                 *PubScreenName = "Workbench";
  35. APTR                   VisualInfo = NULL;
  36. struct Window         *MainWnd = NULL;
  37. struct Gadget         *MainGList = NULL;
  38. struct IntuiMessage    MainMsg;
  39. UWORD                  MainZoom[4];
  40. struct Gadget         *MainGadgets[5];
  41. UWORD                  MainLeft = 20;
  42. UWORD                  MainTop = 20;
  43. UWORD                  MainWidth = 414;
  44. UWORD                  MainHeight = 171;
  45. UBYTE                 *MainWdt = (UBYTE *)"x";
  46. struct TextAttr       *Font, Attr;
  47. UWORD                  FontX, FontY;
  48. UWORD                  OffX, OffY;
  49. struct TextFont       *MainFont = NULL;
  50.  
  51. UWORD MainGTypes[] = {
  52.     LISTVIEW_KIND,
  53.     BUTTON_KIND,
  54.     BUTTON_KIND,
  55.     BUTTON_KIND,
  56.     BUTTON_KIND
  57. };
  58.  
  59. struct NewGadget MainNGad[] = {
  60.     15, 18, 382, 136, (UBYTE *)"Current patches:", NULL, GD_GadList, PLACETEXT_ABOVE|NG_HIGHLABEL, NULL, (APTR)GadListClicked,
  61.     127, 154, 78, 13, (UBYTE *)"Update", NULL, GD_GadUpDate, PLACETEXT_IN, NULL, (APTR)GadUpDateClicked,
  62.     208, 154, 78, 13, (UBYTE *)"About", NULL, GD_GadAbout, PLACETEXT_IN, NULL, (APTR)GadAboutClicked,
  63.     310, 154, 78, 13, (UBYTE *)"Close", NULL, GD_GadClose, PLACETEXT_IN, NULL, (APTR)GadCloseClicked,
  64.     25, 154, 78, 13, (UBYTE *)"Hide", NULL, GD_GadHide, PLACETEXT_IN, NULL, (APTR)GadHideClicked
  65. };
  66.  
  67. ULONG MainGTags[] = {
  68.     (GTLV_ScrollWidth), 18, (GTLV_ReadOnly), TRUE, (TAG_DONE),
  69.     (TAG_DONE),
  70.     (TAG_DONE),
  71.     (TAG_DONE),
  72.     (TAG_DONE)
  73. };
  74.  
  75. static UWORD ComputeX( UWORD value )
  76. {
  77.     return(( UWORD )((( FontX * value ) + 4 ) / 8 ));
  78. }
  79.  
  80. static UWORD ComputeY( UWORD value )
  81. {
  82.     return(( UWORD )((( FontY * value ) + 4 ) / 8 ));
  83. }
  84.  
  85. static void ComputeFont( UWORD width, UWORD height )
  86. {
  87.     Forbid();
  88.     Font = &Attr;
  89.     Font->ta_Name = (STRPTR)GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
  90.     Font->ta_YSize = FontY = GfxBase->DefaultFont->tf_YSize;
  91.     FontX = GfxBase->DefaultFont->tf_XSize;
  92.     Permit();
  93.  
  94.     OffX = Scr->WBorLeft;
  95.     OffY = Scr->RastPort.TxHeight + Scr->WBorTop + 1;
  96.  
  97.     if ( width && height ) {
  98.         if (( ComputeX( width ) + OffX + Scr->WBorRight ) > Scr->Width )
  99.             goto UseTopaz;
  100.         if (( ComputeY( height ) + OffY + Scr->WBorBottom ) > Scr->Height )
  101.             goto UseTopaz;
  102.     }
  103.     return;
  104.  
  105. UseTopaz:
  106.     Font->ta_Name = (STRPTR)"topaz.font";
  107.     FontX = FontY = Font->ta_YSize = 8;
  108. }
  109.  
  110. int SetupScreen( void )
  111. {
  112.     if ( ! ( Scr = LockPubScreen( PubScreenName )))
  113.         return( 1L );
  114.  
  115.     ComputeFont( 0, 0 );
  116.  
  117.     if ( ! ( VisualInfo = GetVisualInfo( Scr, TAG_DONE )))
  118.         return( 2L );
  119.  
  120.     return( 0L );
  121. }
  122.  
  123. void CloseDownScreen( void )
  124. {
  125.     if ( VisualInfo ) {
  126.         FreeVisualInfo( VisualInfo );
  127.         VisualInfo = NULL;
  128.     }
  129.  
  130.     if ( Scr        ) {
  131.         UnlockPubScreen( NULL, Scr );
  132.         Scr = NULL;
  133.     }
  134. }
  135.  
  136. int HandleMainIDCMP( void )
  137. {
  138.     struct IntuiMessage    *m;
  139.     int            (*func)();
  140.     BOOL            running = TRUE;
  141.  
  142.     while( m = GT_GetIMsg( MainWnd->UserPort )) {
  143.  
  144.         CopyMem(( char * )m, ( char * )&MainMsg, (long)sizeof( struct IntuiMessage ));
  145.  
  146.         GT_ReplyIMsg( m );
  147.  
  148.         switch ( MainMsg.Class ) {
  149.  
  150.             case    IDCMP_REFRESHWINDOW:
  151.                 GT_BeginRefresh( MainWnd );
  152.                 GT_EndRefresh( MainWnd, TRUE );
  153.                 break;
  154.  
  155.             case    IDCMP_CLOSEWINDOW:
  156.                 running = MainCloseWindow();
  157.                 break;
  158.  
  159.             case    IDCMP_GADGETUP:
  160.             case    IDCMP_GADGETDOWN:
  161.                 func = ( void * )(( struct Gadget * )MainMsg.IAddress )->UserData;
  162.                 running = func();
  163.                 break;
  164.         }
  165.     }
  166.     return( running );
  167. }
  168.  
  169. int OpenMainWindow( void )
  170. {
  171.     struct NewGadget    ng;
  172.     struct Gadget    *g;
  173.     UWORD        lc, tc;
  174.     UWORD        wleft = MainLeft, wtop = MainTop, ww, wh;
  175.  
  176.     ComputeFont( MainWidth, MainHeight );
  177.  
  178.     ww = ComputeX( MainWidth );
  179.     wh = ComputeY( MainHeight );
  180.  
  181.     if (( wleft + ww + OffX + Scr->WBorRight ) > Scr->Width ) wleft = Scr->Width - ww;
  182.     if (( wtop + wh + OffY + Scr->WBorBottom ) > Scr->Height ) wtop = Scr->Height - wh;
  183.  
  184.     if ( ! ( MainFont = OpenDiskFont( Font )))
  185.         return( 5L );
  186.  
  187.     if ( ! ( g = CreateContext( &MainGList )))
  188.         return( 1L );
  189.  
  190.     for( lc = 0, tc = 0; lc < Main_CNT; lc++ ) {
  191.  
  192.         CopyMem((char * )&MainNGad[ lc ], (char * )&ng, (long)sizeof( struct NewGadget ));
  193.  
  194.         ng.ng_VisualInfo = VisualInfo;
  195.         ng.ng_TextAttr   = Font;
  196.         ng.ng_LeftEdge   = OffX + ComputeX( ng.ng_LeftEdge );
  197.         ng.ng_TopEdge    = OffY + ComputeY( ng.ng_TopEdge );
  198.         ng.ng_Width      = ComputeX( ng.ng_Width );
  199.         ng.ng_Height     = ComputeY( ng.ng_Height);
  200.  
  201.         MainGadgets[ lc ] = g = CreateGadgetA((ULONG)MainGTypes[ lc ], g, &ng, ( struct TagItem * )&MainGTags[ tc ] );
  202.  
  203.         while( MainGTags[ tc ] ) tc += 2;
  204.         tc++;
  205.  
  206.         if ( NOT g )
  207.             return( 2L );
  208.     }
  209.  
  210.     MainZoom[0] = MainLeft;
  211.     MainZoom[1] = MainTop;
  212.     if ( MainWdt )
  213.         MainZoom[2] = TextLength( &Scr->RastPort, (UBYTE *)MainWdt, strlen((char *)MainWdt )) + 80;
  214.     else
  215.         MainZoom[2]  = 80L;
  216.         MainZoom[3] = Scr->WBorTop + Scr->RastPort.TxHeight + 1;
  217.  
  218.     if ( ! ( MainWnd = OpenWindowTags( NULL,
  219.                 WA_Left,    wleft,
  220.                 WA_Top,        wtop,
  221.                 WA_Width,    ww + OffX + Scr->WBorRight,
  222.                 WA_Height,    wh + OffY + Scr->WBorBottom,
  223.                 WA_IDCMP,    LISTVIEWIDCMP|BUTTONIDCMP|IDCMP_CLOSEWINDOW|IDCMP_REFRESHWINDOW,
  224.                 WA_Flags,    WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_RMBTRAP,
  225.                 WA_Gadgets,    MainGList,
  226.                 WA_Title,    MainWdt,
  227.                 WA_ScreenTitle,    "The PatchLib-Solution PALIS (c)1995 by Hans Bühler: Codex Design Software",
  228.                 WA_Zoom,    MainZoom,
  229.                 WA_AutoAdjust,    TRUE,
  230.                 WA_PubScreenFallBack,    TRUE,
  231.                 TAG_DONE )))
  232.     return( 4L );
  233.  
  234.     GT_RefreshWindow( MainWnd, NULL );
  235.  
  236.     return( 0L );
  237. }
  238.  
  239. void CloseMainWindow( void )
  240. {
  241.     if ( MainWnd        ) {
  242.         CloseWindow( MainWnd );
  243.         MainWnd = NULL;
  244.     }
  245.  
  246.     if ( MainGList      ) {
  247.         FreeGadgets( MainGList );
  248.         MainGList = NULL;
  249.     }
  250.  
  251.     if ( MainFont ) {
  252.         CloseFont( MainFont );
  253.         MainFont = NULL;
  254.     }
  255. }
  256.  
  257.